<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
   <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/home.css"/>
	<script src="js/jquery-2.1.0.js"></script>
	<script>
	$(function(){
		var search = $("#search");
		search.click(function(){
			var goodsName = $("#goodsName").val();
			$.ajax("/fengwei/search/goodsByGoodsName",{
				type:"get",
				data:{
					'goodsName':goodsName
				},
				success:function(data){
//                      在这里注册成功后跳转页面
					console.log(data);
					var dataObj = eval('('+data+')');
					$("#goodsName").innerHTML = null;
					if(dataObj.length == 0){
						document.getElementById("Item").innerHTML = "<span style='font-size: 20px;color: red;'>对不起，目前该商品还没入库。请查询其他的商品。</span>"
					} else{
						setGoodsValue(dataObj);
					}
				},
				error:function(){
					alert(0);
				}
			})
		});
		function setGoodsValue(dataObj){
			var Item = document.getElementById("Item");
			for(var i = 0;i < dataObj.length;i++){
				var goodsName = dataObj[i].goodsName;
				var goodsPrice = dataObj[i].goodsPrice;
				var goodsCity = dataObj[i].goodsCity;
				var goodsSchool = dataObj[i].goodsSchool;
				var goodsUnit = dataObj[i].goodsUnit;
				var goodsId = dataObj[i].goodsId;
				var arr = dataObj[i].fileUrl.split("\\");
				var src = arr[arr.length-2]+"/"+arr[arr.length-1];

				var newDiv = document.createElement("div");
				newDiv.id = "search1";
//				newDiv.class = "search2";
				newDiv.setAttribute('class','search');
				Item.appendChild(newDiv);

				newDiv.innerHTML = "<img src='"+src+"'/>"+
						"<div id='search_msg' style='width: 50%;float: right;'>商品名称：<span>'"+goodsName+"'</span><br/>" +
						"商品价格：<span>'"+goodsPrice+goodsUnit+"'</span><br/>商品城市：<span>'"+goodsCity+"'</span><br/>" +
						"商品学校：<span>'"+goodsSchool+"'</span><br/></div>";
				var totalHeight = 0;
				totalHeight += $('#search1').outerHeight(true);
				if(totalHeight>$(window).height()){
					console.log($(window).height());
					$('#Item').css('height',$(window).height()).css('overflow','scroll');
				}
				$(".search").click(function(){
					var count=$(this).index();
					window.location.href = "details.html?goodsId="+dataObj[count].goodsId+"";
				})
			}
		}
	})

	</script>
</head>
<body>
	<div id="head">     <!--头部 搜索框-->
		<a href="Home.html" style="text-decoration: none;display: inline-block;height: 20px;position: absolute;top: 8px;left: 4px;"><img src="img/return.png" width="30px" height="30px" alt=""/></a>
		<input type="search" class="" value=""  id="goodsName"/>
		<input type="button" value="搜索" id="search" style="width:50px;border: none;background: red;color: white;font-size: 15px;">
	</div>
<div id="Item" style="width: 100%;">

</div>
</body>
</html>